<?php

/**
 * Description of SecureManager
 *
 * @author agniuek
 */
class SecureManager {
    /*
     * sanitize
     * @param
     */

    public function sanitize($argString) {
        $buf = "";
        $vowels = array(";", "|", "\"", "x00", "x08", "x7f", "x20", "x04", "x0D", "x1b", "*", "&lt;", "&gt;", "\'", "../");
        $buf = str_replace($vowels, "", $argString);
        return $buf;
    }

    /**
     * Helper function to check whether a session token has been set
     *
     * @return boolean Returns true if a session token has been set
     */
    public function authenticated() {
        if (!isset($_SESSION['sessionToken'])) {
            return false;
        } else {
            $token = $_SESSION['sessionToken'];
            if (empty($token)) {
                return false;
            }
            return true;
        }
    }

// k.kodama
    function get_tiny_url($long_url = '',$developerKey) {
        $api_url = 'https://www.googleapis.com/urlshortener/v1/url';
        $api_key = 'AIzaSyAESV7vBfJg4xgsKxs8f6Y_lxyotzA2vMo';
        if(!empty($developerKey)){
         $api_key = $developerKey;
        }
        $curl = curl_init("$api_url?key=$api_key");
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, '{"longUrl":"' . $long_url . '"}');
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $res = curl_exec($curl);
        curl_close($curl);
        $json = json_decode($res);
        $tiny_url = $json->id;
        return $tiny_url;
    }

}

